package com.mobile.framework.upload;

/**
 * Created by IntelliJ IDEA.
 * User: bj
 * Date: 2010-6-22
 * Time: 11:18:44
 * To change this template use File | Settings | File Templates.
 */
import java.text.SimpleDateFormat;
import java.util.Date;


public class FileType {
	/**
	 * �Զ�����ļ���
	 * @param fileName
	 * @return
	 */
	public static String autoFileName(String fileName) {
		if(fileName==null || fileName.trim().length()<3 || fileName.indexOf(".")

<=0)
			return null;
		else {
			//��ȡ�ļ�����
			String type = fileName.substring(fileName.lastIndexOf

("."),fileName.length());
			//��ݺ�����������
			SimpleDateFormat format=new SimpleDateFormat("yyyyMMddHHmmss");
			String auto = format.format(new Date());
			return auto + Math.round(Math.random()*10000) + type;
		}
	}

	/**
	 * �Զ���ɶ������
	 * @return
	 */
	public static String autoOrderNum() {
		//��ݺ�����������
		SimpleDateFormat format=new SimpleDateFormat("yyyyMMddHHmmss");
		String auto = format.format(new Date());
		return auto + Math.round(Math.random()*10000);
	}

	/*
	 * �����ϴ�ͼƬ�ĺ�׺,kindָ�����ϴ���ͼƬ��׺
	 * �޸�:longbo
	 * �޸�����:2008-4-28
	 */
	public boolean isSameFileType(String filename ,String kind){

		if(filename!=null&& kind!=null&&!filename.equals("")&&!kind.equals(""))
		{

			String type = filename.substring(filename.lastIndexOf(".")

+1,filename.length());
			//System.out.println(type);
			if(kind.toLowerCase().equals(type.toLowerCase()))
				return true;


//			if(kind.indexOf(type)>=0){
//			    //����ļ����Ͱ������?Χ����У��ɹ�
//		        return  true;
//			}
			return  false;

		}else{

			return  false;
		}

	}
	/*
	 * �����ϴ�ͼƬ�ĺ�׺
	 */
	public boolean  isSameFileType(String filename){
		String kind="jpg,jpeg,gif,png,bmp,doc,pdf";//ָ�����ϴ���ͼƬ��׺
		if(filename!=null&& kind!=null&&!filename.equals("")&&!kind.equals(""))
		{

			String type = filename.substring(filename.lastIndexOf(".")

+1,filename.length());
			//System.out.print("fileTyope="+type);
			if(kind.indexOf(type.toLowerCase())>=0){
			    //����ļ����Ͱ������?Χ����У��ɹ�
		        return  true;
			}
			return  false;

		}else{

			return  false;
		}

	}


	/**
	 * author:lixiang
	 * see:�Ƚ��ļ��Ƿ��Ǻϸ�ĸ�ʽ
	 * ���ڶ����ļ���ʽ��У��
	 * 2008-4-12
	 * @return
	 */

	public boolean  compareFileType(String filename ,String kind){

		if(filename!=null&& kind!=null&&!filename.equals("")&&!kind.equals(""))
		{
			if(filename.length()<3||kind.length()!=3){

		    return  false;
			}else{
				String type = filename.substring(filename.lastIndexOf

("."),filename.length());
			   if(filename.indexOf(type)>0){
				   //����ļ����Ͱ������?Χ����У��ɹ�
				  return  true;

			   }
			return  false;
			}
		}else{

			return  false;
		}

	}



  public  String  fileNameCreate(){

	  SimpleDateFormat   simpledateformat;
      simpledateformat   =   new   SimpleDateFormat( "yyyyMMddHHmmss");
      Date   dt=new   Date();
      String   strDate=simpledateformat.format(dt);
      System.out.print(strDate);

      return   strDate;
  }
  public String getFileType(String filename ){

	  if(filename!=null&&!filename.equals("")){
	  filename=filename.substring(filename.length()-4, filename.length());
	  }
	  return   filename;

  }

  public static void main(String[] args) {
	  FileType t = new FileType();
	  System.out.println(t.isSameFileType("145.jpg","jpg"));
//	  System.out.println(t.autoOrderNum());
//	  t = new FileType();
//	  System.out.println(t.autoFileName("aa.pm"));
//	  t = new FileType();
//	  System.out.println(t.autoFileName("aa.pm"));
  }
}

